package com.mmall.service;

import com.mmall.model.MyConfigAttribute;
import com.mmall.model.SysAcl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.stereotype.Repository;

import java.util.*;

@Scope(value = "prototype")
@Repository("securityMetadataService")
public class SecurityMetadataService {
	@Autowired(required = true)
	@Qualifier("sysAclService")
	private SysAclService sysAclService;
	/* (non-Javadoc)
	 * @see com.authority.dao.SecurityMetadataDao#getMetadata()
	 */
	public Map<String, Collection<ConfigAttribute>> getMetadata() {
		Map<String, Collection<ConfigAttribute>> configResource = new HashMap<String, Collection<ConfigAttribute>>();
		List<SysAcl> list = sysAclService.getAll();
		Collection<ConfigAttribute> configList = null;
		for(SysAcl sysAcl:list){

			MyConfigAttribute configAttribute = new MyConfigAttribute();
			configAttribute
					.setAttribute(sysAcl.getCode());
			configList =new ArrayList<ConfigAttribute>();
			configList.add(configAttribute);
			configResource.put(sysAcl.getUrl(), configList);
		}
		return configResource; // To change body of implemented methods use File
								// | Settings | File Templates.
	}




}
